package com.weavernorth.humanresource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.integration.util.SessionUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: ecology_erdos
 * @description:
 * @author: zm
 * @create: 2019-12-02 10:38
 **/


public class AutoLogin {
    private static Log newlog = LogFactory.getLog(AutoLogin.class);

    /**
     * 构造用户session并获取转发地址
     *
     * @param loginid 登录名
     * @return 跳转地址
     */
    public String createUserSessionAndGetDispatcherUrl(String loginid) {
        RecordSet rs = new RecordSet();

        //查询OA中是否有username的人员

        String sql = "select * from HrmResource where mobile='" + loginid + "'";
        newlog.error("当前用户信息==" + sql);
        rs.execute(sql);
        User user_new = null;
        if (rs.next()) {
            String uid = rs.getString("id");
            return uid;
        } else {
            //OA中查无此人，必须重新登录
            return "OA中查无此人，必须重新登录";

        }
    }

    /**
     * 根据人员查找当前的requestid
     *
     * @param strUserid
     * @return
     */
    public String getRequestid(String strUserid) {
        String strRequestid = "";
        //数据库操作
        RecordSet rs = new RecordSet();
        //查询sql
        String strSql = "select requestid  from workflow_currentoperator  where userid='" + strUserid + "' order by requestid desc";
        newlog.info("获取当前requesitd" + strSql);
        rs.execute(strSql);
        if (rs.next()) {
            strRequestid = Util.null2String(rs.getString("requestid"));
        }
        newlog.info("返回requestid"+strRequestid);

        return strRequestid;
    }

}
